<?php
/*通过json参数将Data.object中相应的数据格式化输出*/
class SwitchType{
    protected $data='';
    protected $dataList='';//从Data.object中取回的数据
    protected $wiringString=array();//需要返回的的数据
    public function __construct($jsonArray,$dataList){
        $this->data=$jsonArray;
        $this->dataList=$dataList;
    }
    //根据参数判断来实例化控制类型
    static public function Actions($jsonArray){
        $wiringArray='';
        foreach($jsonArray as $k=>$v){
            switch($k){
                case 'alones'://公寓单独户型
                    $actions=new Alones($jsonArray[$k],Datas::to('alonesList'));
                    break;
                case 'floors'://公寓整层
                    $actions=new Floors($jsonArray[$k],Datas::to('alonesList'));
                    break;
                case 'alls'://全部
                    $actions=new Alls($jsonArray[$k],Datas::to('alls'));
                    break;
                default://写字楼、避难所、会所
                    $arrayKey=$k.'List';
                    $actions=new Other($jsonArray[$k],Datas::to($arrayKey),$k);
            }
            $wiringArray=$actions->returnData();
        }
        return $wiringArray;
    }
}
//独立户型
class Alones extends SwitchType{
    public function __construct($jsonArray,$dataList){
        parent::__construct($jsonArray,$dataList);
    }
    public function returnData(){
        $number=$this->data['number'];
        $floor=$this->data['floor'];
        $static=$this->data['static'];
        $wiring=$this->dataList[$number][$floor] or die('参数传递错误');
        $this->wiringArray['switch']='alones';
        $this->wiringArray[$wiring]=$static;
        return $this->wiringArray;
    }
}
//楼层
class Floors extends SwitchType{
    public function __construct($jsonArray,$dataList){
        parent::__construct($jsonArray,$dataList);
    }
    public function returnData(){
        $floor=$this->data['floor'];
        $static=$this->data['static'];
        foreach ($this->dataList as $k => $v) {
            $wiringArray[$v[$floor]]=$static;
        }
        $wiringArray['switch']='floors';
        return $wiringArray;
    }
}
//写字楼、避难所、会所
class Other extends SwitchType{
    private $key='';
    public function __construct($jsonArray,$dataList,$key){
        parent::__construct($jsonArray,$dataList);
        $this->key=$key;
    }
    public function returnData(){
        $floor=$this->data['floor'];
        $static=$this->data['static'];
        $wiring=$this->dataList[$floor];
        $this->wiringArray['switch']=$this->key;
        $this->wiringArray[$wiring]=$static;
        return $this->wiringArray;
    }
}
//全部
class Alls extends SwitchType{
    public function __construct($jsonArray,$dataList){
        parent::__construct($jsonArray,$dataList);
    }
    public function returnData(){
        $static=$this->data['static'];
        foreach ($this->dataList as $k => $v) {
            $this->wiringArray[$v]=$static;
        }
        $this->wiringArray['switch']='alls';
        return $this->wiringArray;
    }
}
?>